package com.cynteka.cyfoman.ui;

import com.cynteka.cyfoman.core.ValueObject;
import com.cynteka.cyfoman.core.config.ActionMD;

import java.awt.*;

/**
 * User: Sergey
 * Date: 03.08.11
 * Time: 13:26
 */
public class ActionMDListener implements IEventListener {

    private EventDispatcher eventDispatcher;

    public ActionMDListener() {
    }

    @Override
    public void handleEvent(IEvent event) {
        if (event instanceof ActionMDEvent) {
            ActionMDEvent actionEvent = (ActionMDEvent) event;
            final ActionMD action = actionEvent.getAction();

            final ValueObject valueObject = new ValueObject();

            ActionParamDlg paramDlg = new ActionParamDlg(action, valueObject) {
                @Override
                protected void onOK() {
                    super.onOK();
                    // ActionProcessor.processAction(action, valueObject, baseFolder, dataSource, filesToCopy);
                    valueObject.firePrepareToBeStored();
                    eventDispatcher.sendEvent(new StoreEvent(valueObject, action));
                    eventDispatcher.sendEvent(new UIEvent(UIEvent.REFRESH));
                }
            };
            paramDlg.pack();
            Dimension size = paramDlg.getSize();
            paramDlg.setSize(size.width + 50, size.height);
            paramDlg.setLocationRelativeTo(null);

            paramDlg.setVisible(true);
        }

    }

    public EventDispatcher getEventDispatcher() {
        return eventDispatcher;
    }

    public void setEventDispatcher(EventDispatcher eventDispatcher) {
        this.eventDispatcher = eventDispatcher;
    }
}
